package ObserverMode

//气象局提供的,天气数据核心类
class WeatherData {
  private var tmeperature: Float = _
  private var pressure: Float = _
  private var humidity: Float = _
  private var currentconditions: currentConditions = _

  def this(currentConditions: currentConditions) {
    this
    this.currentconditions = currentConditions
  }

  def getTemperature() = this.tmeperature

  def getPressure() = this.pressure

  def getHumity() = this.humidity

  def setData(mt: Float, mP: Float, mH: Float): Unit = {
    this.tmeperature = mt
    this.pressure = mP
    this.humidity = mH
    //要求修改公告板的最新数据
    dataChange()
  }

  def dataChange(): Unit = {
    currentconditions.update(getTemperature(), getPressure(), getHumity())
  }

}

//气象局的天气公告
class currentConditions {
  private var tmeperature: Float = _
  private var pressure: Float = _
  private var humidity: Float = _

  def update(mt: Float, mP: Float, mH: Float): Unit = {
    this.tmeperature = mt
    this.pressure = mP
    this.humidity = mH
    display()
  }

  def display(): Unit = {
    println("today temperature:" + tmeperature)
    println("today Pressure:" + pressure)
    println("today Humidity:" + humidity)
  }
}
